package com.codefish;

/**
 * A股票价格关注者
 *
 * @author codefish
 * @version 1.0
 * @date 2022/05/07 下午 04:30
 */
public class NowPriceObserver extends StockObserver {
    /**
     * 订阅的发布者
     */
    StockPublisher publisher;
    /**
     * 构造函数
     * @param name 订阅者标识
     * @param publisher 订阅的发布者对象
     */
    public NowPriceObserver(String name, StockPublisher publisher) {
        super.name = name;
        this.publisher = publisher;
    }

    @Override
    public void execute() {
        if(publisher instanceof AStockPublisher) {
            double price = ((AStockPublisher) publisher).getPrice();
            System.out.println(name + ":当前股票价格为" + price);
        }
    }
}
